package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.EticketNumVO;
import com.jishuo.nontax.bfc.service.EticketNumService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 电子缴款查询
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/eticketnum",name = "电子票缴费单据")
@UserAuthority(menu={"bill/eticketnum/eticketnum","sys/basedata/basedata"})
public class EticketNumController {

    @Resource
    private EticketNumService eticketNumService;
    @Resource
    private UserService userService;

    private String prefix = "bill/";

    @RequestMapping(value = {"eticketnum"}, name = "电子票首页")
    public String index(@PathVariable(required = false) String page) {
        return prefix + "eticketnum";
    }

    @ResponseBody
    @RequestMapping(value = "listEticketNum",name = "电子票缴费列表")
    public GridResult<EticketNumVO> listEticketNum(EticketNumVO eticketNumVO , Pagination pagination){
        return new GridResult<>(eticketNumService.listEticketNum(eticketNumVO,pagination));
    }



    @ResponseBody
    @RequestMapping(value = "sendEticketNum", name = "发送电子缴款信息")
    public BaseResult sendEticketNum(@RequestParam String billids, String usercode, String userpwd, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return eticketNumService.sendEticketNum(billids);
    }

    @ResponseBody
    @RequestMapping(value = "cleanEticketNum", name = "冲销电子缴款信息")
    public BaseResult cleanEticketNum(@RequestParam String billids, String usercode, String userpwd, HttpSession session) throws  Exception{
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return eticketNumService.cleanEticketNum(billids, usercode);

    }
}
